package com.miaoda.miaoda_ai.core.saver;

import cn.hutool.core.util.ObjectUtil;
import com.miaoda.miaoda_ai.ai.model.MultiFileCodeResult;
import com.miaoda.miaoda_ai.model.enums.CodeGenTypeEnum;

public class MultiCodeSaverTemplate extends CodeFileSaverTemplate<MultiFileCodeResult>{
    @Override
    protected String saveFiles(MultiFileCodeResult codeResult, Long appId) {
        String dirPath = buildUniqueFilePath(appId);
        saveCodeToFile(codeResult.getHtmlCode(), "index.html",dirPath);
        saveCodeToFile(codeResult.getCssCode(), "style.css",dirPath);
        saveCodeToFile(codeResult.getJsCode(), "script.js",dirPath);
        return dirPath;
    }

    @Override
    public void validateInput(MultiFileCodeResult codeResult) {
        if (ObjectUtil.isEmpty(codeResult)){
            throw new RuntimeException("输入不能为空");
        }
    }

    @Override
    public CodeGenTypeEnum getCodeGenType() {
        return CodeGenTypeEnum.MULTI_FILE;
    }
}
